<template>
  <nav class="home-nav">
    <div class="container">
      <ul>
        <template v-if="userInfo.token">
          <li>
            <a href="javascript:;"><i class="iconfont icon-user"></i>{{userInfo.nickname}}</a>
          </li>
          <li><a href="javascript:;" @click="logout">退出登陆</a></li>
        </template>
        <template v-else>
          <li>
            <RouterLink to="/login">请先登录</RouterLink>
          </li>
          <li><a href="javascript:;">免费注册</a></li>
        </template>
        <li><a href="javascript:;">我的订单</a></li>
        <li><a href="javascript:;">会员中心</a></li>
        <li><a href="javascript:;">帮助中心</a></li>
        <li><a href="javascript:;">关于我们</a></li>
        <li>
          <a href="javascript:;"><i class="iconfont icon-phone"></i>手机版</a>
        </li>
      </ul>
    </div>
  </nav>
</template>
<script>
import { useStore } from 'vuex'
import { defineComponent, computed } from 'vue'
import { useRouter } from 'vue-router'
import { SET_USER } from '@/store/modules/actionTypes'
import { debounce } from 'lodash-es'

export default defineComponent({
  name: 'home-nav',
  setup() {
    const store = useStore()
    const userInfo = computed(() => {
      return store.state.user.userInfo
    })
    const router = useRouter()
    const logout = () => {
      store.commit(`user/${SET_USER}`, {})
      router.push('/login')
    }

    return { userInfo, logout }
  }
})
</script>
<style lang="less" scoped>
.home-nav {
  background: #333;
  .container {
    ul {
      display: flex;
      height: 53px;
      justify-content: flex-end;
      align-items: center;
      li {
        a {
          padding: 0 15px;
          color: #cdcdcd;
          line-height: 1;
          display: inline-block;
          i {
            font-size: 14px;
            margin-right: 2px;
          }
        }
      }
    }
  }
}
</style>